﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace CuocChienQueNha.Class.Basic
{
    public class ButtonGame
    {
        public Texture2D image { get; set; }
        public Vector2 position { get; set; }
        public Vector2 size { get; set; }
        public float scale { get; set; }
        public string linkImg { get; set; }
        public string name { get; set; }
        public bool isTouched { get; set; }
        public bool isEnable { get; set; }

        public ButtonGame() { }
        public ButtonGame(string name, string link, Vector2 position, Vector2 size, float scale)
        {
            this.name = name;
            this.linkImg = link;
            this.position = position;
            this.size = size;
            this.scale = scale;
            isTouched = false;
            isEnable = true;
        }
        public virtual void Load(ContentManager content)
        {
            image = content.Load<Texture2D>(linkImg);
        }
        public virtual void Draw(SpriteBatch sprite)
        {
            sprite.Draw(image, position - (isTouched ? new Vector2(size.X / 2, size.Y) * 0.1f : Vector2.Zero), new Rectangle(isTouched ? (int)(size.X / 2) : 0, 0, (int)size.X / 2, (int)size.Y), Color.White, 0f, Vector2.Zero, (isTouched ? scale + 0.2f : scale), SpriteEffects.None, 0);
        }
        public void Draw(SpriteBatch sprite, bool isEnable)
        {
            this.isEnable = isEnable;
            if (!isEnable)
            {
                sprite.Draw(image, position, new Rectangle((int)(size.X * 2 / 3), 0, (int)size.X / 3, (int)size.Y), Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0);
            }
            else
            {
                sprite.Draw(image, position - (isTouched ? new Vector2(size.X / 3, size.Y) * 0.1f : Vector2.Zero), new Rectangle(isTouched ? (int)(size.X / 3) : 0, 0, (int)size.X / 3, (int)size.Y), Color.White, 0f, Vector2.Zero, (isTouched ? scale + 0.2f : scale), SpriteEffects.None, 0);
            }
        }
        public virtual bool isTouch(Vector2 touch)
        {
            if (touch.X >= position.X && touch.Y >= position.Y && touch.X <= (position.X + scale * size.X / 2) && touch.Y <= (position.Y + size.Y * scale))
            {
                isTouched = true;
                return true;
            }
            else
            {
                isTouched = false;
                return false;
            }
        }
        public virtual bool isTouch(Vector2 touch,bool isEnable)
        {
            if (!isEnable) return false;
            if (touch.X >= position.X && touch.Y >= position.Y && touch.X <= (position.X + scale * size.X / 3) && touch.Y <= (position.Y + size.Y * scale))
            {
                isTouched = true;
                return true;
            }
            else
            {
                isTouched = false;
                return false;
            }
        }
    }
}
